package m

import (
	"GameServer/Common/utils"
	"GameServer/Game/dbmodule"

	"github.com/globalsign/mgo/bson"
)

type RecomFriend struct {
	Uid  bson.ObjectId `bson:"_id" json:"_uid"`
	Name string        `bson:"name" json:"name"`
}

func FindRecomFriend(u *User, page, limit int, lst []string) (r []*RecomFriend) {
	r = make([]*RecomFriend, 0)
	nin := make([]interface{}, 0)
	for _, item := range lst {
		nin = append(nin, bson.ObjectIdHex(item))
	}
	err := dbmodule.MgoDB.GameDB.FindPageSort("user", 1, 30, bson.M{"_id": bson.M{"$nin": nin}}, bson.M{"name": 1}, []string{"-last_login_time"}, &r)
	if err != nil {
		return
	}
	return
}

// 推荐一个好友
func FindRecomFriendOne(us *User, page, limit int, lst []string) (r *User) {
	uLst := make([]*User, 0)
	nin := make([]interface{}, 0)
	for _, item := range lst {
		nin = append(nin, bson.ObjectIdHex(item))
	}
	err := dbmodule.MgoDB.GameDB.FindPageSort("user", page, limit, bson.M{"_id": bson.M{"$nin": nin}}, nil, []string{"-last_login_time"}, &uLst)
	if err != nil {
		return
	}
	idx := utils.RandomInt(0, len(uLst))
	r = uLst[idx]
	return
}
